/* 
 * File:   sharpening_spatial_filter.cpp
 * Author: dima
 * 
 * Created on 28 Январь 2015 г., 13:53
 */
#include <iostream>
#include "ipd_sharpening_spatial_filter.h"

namespace ipd
{

ipd_sharpening_spatial_filter::ipd_sharpening_spatial_filter(ipd_img &img) : ipd_filter(img)
{
}

ipd_sharpening_spatial_filter::~ipd_sharpening_spatial_filter()
{
}

void ipd_sharpening_spatial_filter::init(tp_sharpening_spatial_filter tp_filter) //object initialization
{
    width_mask = height_mask = 3;
    int const sz = 9;
    int maska[sz];
    switch (tp_filter)
    {
    case component_mask_laplacian_1://Component mask Laplacian
    {
        maska[0] = 0;
        maska[1] = -1;
        maska[2] = 0;
        maska[3] = -1;
        maska[4] = 5;
        maska[5] = -1;
        maska[6] = 0;
        maska[7] = -1;
        maska[8] = 0;
        break;
    }
    case component_mask_laplacian_2://Another component mask Laplacian
    default:
    {
        maska[0] = -1;
        maska[1] = -1;
        maska[2] = -1;
        maska[3] = -1;
        maska[4] = 9;
        maska[5] = -1;
        maska[6] = -1;
        maska[7] = -1;
        maska[8] = -1;
        break;
    }
    }
    ipd_filter::init(width_mask, height_mask, maska);
}

void ipd_sharpening_spatial_filter::get_pixel(unsigned char *pixel) //get normalized pixel
{
    int max_color = original_image.get_max_color();
    int min_color = original_image.get_min_color();
    switch (img_model)
    {
    case ipd::tp_RGB:
    {
        for (int i = 0; i < sz_RGB; i++)
            pixel[i] = sum[i] > max_color ? max_color : sum[i] < min_color ? min_color : sum[i];
        break;
    }
    case ipd::tp_mono:
    {
        pixel[0] = sum[0] > max_color ? max_color : sum[0] < min_color ? min_color : sum[0];
        break;
    }
    }
}

ipd_sharpening_spatial_filter::ipd_sharpening_spatial_filter(const ipd_sharpening_spatial_filter& orig) : ipd_filter(orig)
{

}

}